~ chicken-core (chicken-5) /manual/Module (chicken fixnum)
Trap1[[tags: manual]]
2[[toc:]]
3
4== Module (chicken fixnum)
5
6Because CHICKEN supports a full numeric tower, operations can
7sometimes incur a substantial overhead to simply detect the type of numbers
8you're passing in. When you know you're definitely dealing only with
9fixnums, you can choose to use fixnum-specific operations to avoid
10this overhead.
11
12This is purely a performance hack. You might want to consider adding
13[[Types|type annotations]] instead, this often gives the same
14performance boost without having to rewrite all numeric operators in
15your code.
16
17
18=== Arithmetic fixnum operations
19
20<procedure>(fx+ N1 N2)</procedure>
21<procedure>(fx- N1 N2)</procedure>
22<procedure>(fx* N1 N2)</procedure>
23<procedure>(fx/ N1 N2)</procedure>
24<procedure>(fxmod N1 N2)</procedure>
25<procedure>(fxrem N1 N2)</procedure>
26<procedure>(fxneg N)</procedure>
27<procedure>(fxmin N1 N2)</procedure>
28<procedure>(fxmax N1 N2)</procedure>
29<procedure>(fxand N1 N2)</procedure>
30<procedure>(fxior N1 N2)</procedure>
31<procedure>(fxxor N1 N2)</procedure>
32<procedure>(fxnot N)</procedure>
33<procedure>(fxshl N1 N2)</procedure>
34<procedure>(fxshr N1 N2)</procedure>
35<procedure>(fxgcd N1 N2)</procedure>
36
37{{fx+}} and friends are arithmetic fixnum operations. These procedures do not
38check their arguments, so non-fixnum parameters will result in incorrect
39results. {{fxneg}} negates its argument.
40
41On division by zero, {{fx/}}, {{fxmod}} and {{fxrem}} signal a
42condition of kind {{(exn arithmetic)}}.
43
44{{fxshl}} and {{fxshr}} perform arithmetic shift left and right,
45respectively.
46
47=== Overflow-aware fixnum operations
48
49<procedure>(fx+? N1 N2)</procedure>
50<procedure>(fx-? N1 N2)</procedure>
51<procedure>(fx*? N1 N2)</procedure>
52<procedure>(fx/? N1 N2)</procedure>
53
54These procedures behave similarly to their standard counterparts with
55the exception that {{#f}} is returned if an argument is not a fixnum
56or the result of the operation overflows.
57
58Chaining of such procedures is well-defined and causes the overflow
59error to be propagated.
60
61=== Fixnum comparison and predicates
62
63<procedure>(fxodd? N)</procedure>
64<procedure>(fxeven? N)</procedure>
65<procedure>(fx= N1 N2)</procedure>
66<procedure>(fx> N1 N2)</procedure>
67<procedure>(fx< N1 N2)</procedure>
68<procedure>(fx>= N1 N2)</procedure>
69<procedure>(fx<= N1 N2)</procedure>
70
71Comparison of fixnums and predicates on them.
72
73=== Fixnum limits
74
75<constant>most-positive-fixnum</constant><br>
76<constant>most-negative-fixnum</constant><br>
77<constant>fixnum-bits</constant><br>
78<constant>fixnum-precision</constant><br>
79
80Platform-specific fixnum limits.
81
82---
83Previous: [[Module (chicken file posix)]]
84
85Next: [[Module (chicken flonum)]]